@extends('layouts.public')

@section('head')
    <link rel="stylesheet" href="{{cdn('js/plugins/webuploader/single.css')}}">
    <link rel="stylesheet" href="{{cdn('css/bootstrap-select.css')}}">
    <script src="{{cdn('js/bootstrap-select.js')}}"></script>
    <style>
        .items{
            margin-bottom:15px;
        }
        .bootstrap-select  .dropdown-menu > li > a{
            background:#fff;
            color:#333;
        }
        .bootstrap-select .dropdown-menu{
            background:#fff
        }
    </style>
@endsection

@section('bodyattr')class="gray-bg"@endsection

@section('body')
    <div class="wrapper wrapper-content">
        <div class="row m-b">
            <div class="col-sm-12">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li><a href="{{route('admin.good.goods')}}">商品列表</a></li>
                        <li @if(!isset($user))class="active"@endif><a href="{{route('admin.good.goods.add')}}">新增</a></li>
                        @if(isset($user))
                            <li class="active"><a href="#">编辑</a></li>
                        @endif
                    </ul>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form action="{{route('admin.good.goods.save')}}" method="post" class="form-horizontal ajaxForm">
                            <input type="hidden" name="id" value="{{$user->id or 0}}"/>
                           
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商品名称</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" required name="title" @if(isset($user)) value="{{$user->title or ''}}"placeholder="请填写商品名称" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商品标签</label>
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" required name="sign" @if(isset($user)) value="{{$user->sign or ''}}"placeholder="请填写商品标签" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商品地址</label>
                                <div class="col-sm-3">
                                    <input type="text" required class="form-control" name="address" @if(isset($user)) value="{{$user->address or ''}}"placeholder="请填写商品地址" @endif autocomplete="off"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">选择店铺</label>
                                <div class="col-sm-3">
                                    <select name="shop_id" class="selectpicker show-tick form-control" data-live-search="true" required>
                                        <option value="">请选择店铺</option>
                                        @foreach ($shops as $shop)
                                            <option value="{{$shop['id']}}"  @if ((isset($user->shop_id)? $user->shop_id:'')== $shop['id']) selected="selected"@endif>
                                                {{$shop['title']}}
                                            </option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">所属分类</label>
                                <div class="col-sm-3">
                                    <select name="cate_id" class="form-control" required>
                                        <option value="">--请选择分类--</option>
                                        @foreach ($cates as $cate)
                                            @if ($cate['layer'] < 1)
                                                <option value="" disabled="disabled">--{{$cate['cate_name']}}--</option>
                                            @else
                                                <option value="{{$cate['cate_id']}}"
                                                        @if ((isset($user->cate_id) ? $user->cate_id : '') == $cate['cate_id']) selected="selected"@endif>
                                                    &nbsp;&nbsp;&nbsp;&nbsp;{{$cate['cate_name']}}</option>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商品型号 </label>
                                <div class="col-sm-6">
                                    <div class="btn btn-success" id="add_options">+</div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-6 col-sm-offset-2" id="options">
                                    @if(isset($user) && $user->sizes != '')
                                        @foreach(json_decode($user['sizes'],true) as $g)
                                    <div class="row items">
                                        <div class="col-sm-6">

                                            <input type="text"  class="form-control" name="size_name[]" value="{{$g['size_name']}}"  required placeholder="请输入商品型号">
                                        </div>
                                        <div class="col-sm-4">
                                            <input type="text"  class="form-control" name="size_num[]" maxlength="7" value="{{$g['size_num']}}" required  placeholder="请输入商品数量">
                                        </div>
                                        <div class="btn btn-default des">-</div>
                                    </div>
                                        @endforeach
                                    @endif
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商品图片</label>
                                <div class="col-sm-10" id="imgupload">
                                    <div id="filePicker">选择图片</div>
                                    <p style="color:#ccc;font-size:12px">为了更好地展示商品，建议上传400px*300px尺寸图片最佳</p>
                                    @if(isset($user) && $user->default_img != '')
                                        @foreach(explode(',',$user['default_img']) as $g)
                                        <div class="img-div">
                                            <img src="{{get_file_url($g)}}"/>
                                            <span class="cancel">×</span>
                                        </div>
                                        @endforeach
                                    @endif

                                    <input type="hidden" name="default_img"  required id="default_img" value="{{ $user['default_img'] or '' }}"/>


                                    <input type="hidden" name="file_id" id="file_id" value="0"/>
                                </div>

                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">商品详情</label>
                                <div class="col-sm-10">
                                    <textarea name="content" id="content">{{$user->content or ''}}</textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">评论</label>
                                <div class="col-sm-10">
                                    <div class="input-group m-t-xs-2">
                                        <input type="radio" name="is_comment" value="1"
                                               @if ((isset($user->is_comment) ? $user->is_comment : '') != '0') checked="checked"@endif/>允许
                                        <input type="radio" name="is_comment" value="0"
                                               @if ((isset($user->is_comment) ? $user->is_comment : '') == '0') checked="checked"@endif/>不允许
                                    </div>
                                </div>
                            </div>
{{--                            <div class="form-group">--}}
{{--                                <label class="col-sm-2 control-label">包邮</label>--}}
{{--                                <div class="col-sm-10">--}}
{{--                                    <div class="input-group m-t-xs-2">--}}
{{--                                        <input type="radio" name="send_type" value="1"--}}
{{--                                               @if ((isset($user->send_type) ? $user->send_type : '') != '0') checked="checked"@endif/>包邮--}}
{{--                                        <input type="radio" name="send_type" value="0"--}}
{{--                                               @if ((isset($user->send_type) ? $user->send_type : '') == '0') checked="checked"@endif/>不包邮--}}
{{--                                    </div>--}}
{{--                                </div>--}}
{{--                            </div>--}}
                            <div class="form-group">
                                <label class="col-sm-2 control-label">置顶</label>
                                <div class="col-sm-10">
                                    <div class="input-group m-t-xs-2">
                                        <input type="radio" name="is_top" value="1"
                                               @if ((isset($user->is_top) ? $user->is_top : '') == '1') checked="checked"@endif/>置顶
                                        <input type="radio" name="is_top" value="0"
                                               @if ((isset($user->is_top) ? $user->is_top : '') != '1') checked="checked"@endif/>不置顶
                                    </div>
                                </div>
                            </div>
{{--                            <div class="form-group">--}}
{{--                                <label class="col-sm-2 control-label">是否积分兑换</label>--}}
{{--                                <div class="col-sm-10">--}}
{{--                                    <div class="input-group m-t-xs-2">--}}
{{--                                        <input type="radio" name="is_recommend" value="1"--}}
{{--                                               @if ((isset($user->is_exchange) ? $user->is_exchange : '') == '1') checked="checked"@endif/>兑换--}}
{{--                                        <input type="radio" name="is_recommend" value="0"--}}
{{--                                               @if ((isset($user->is_exchange) ? $user->is_exchange : '') != '1') checked="checked"@endif/>不兑换--}}
{{--                                    </div>--}}
{{--                                </div>--}}
{{--                            </div>--}}
{{--                            <div class="form-group">--}}
{{--                                <label class="col-sm-2 control-label">积分兑换</label>--}}
{{--                                <div class="col-sm-6">--}}
{{--                                    <input type="text" name="store" class="form-control" >--}}
{{--                                </div>--}}
{{--                            </div>--}}
                            <div class="form-group">
                                <label class="col-sm-2 control-label">推荐</label>
                                <div class="col-sm-10">
                                    <div class="input-group m-t-xs-2">
                                        <input type="radio" name="is_recommend" value="1"
                                               @if ((isset($user->is_recommend) ? $user->is_recommend : '') == '1') checked="checked"@endif/>推荐
                                        <input type="radio" name="is_recommend" value="0"
                                               @if ((isset($user->is_recommend) ? $user->is_recommend : '') != '1') checked="checked"@endif/>不推荐
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">保存</button>
                                    <button class="btn btn-white" type="button" id="backBtn">返回</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('script')
    <script src="{{cdn('js/plugins/ueditor/ueditor.config.js')}}"></script>
    <script src="{{cdn('js/plugins/ueditor/ueditor.all.min.js')}}"></script>
    <script src="{{cdn('js/plugins/ueditor/lang/zh-cn/zh-cn.js')}}"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            var ue = UE.getEditor('content');

            ue.ready(function () {
                ue.execCommand('serverparam', {
                    '_token': '{{csrf_token()}}',
                    'filetype': 'FT_ARTICLE_DESC',
                    'itemid': '{{$user->id or 0}}'
                });
            });
            $(function(){
                $(".selectpicker" ).selectpicker('refresh');
            })
            $('#add_options').click(function () {
                var str= '<div class="row items">\n' +
                    '                    <div class="col-sm-6">\n' +
                    '                    <input type="text"  class="form-control" name="size_name[]" required placeholder="请输入商品型号">\n' +
                    '                    </div>\n' +
                    '                    <div class="col-sm-4">\n' +
                    '                    <input type="text"  class="form-control" name="size_num[]" required maxlength="7"  placeholder="请输入商品数量">\n' +
                    '                    </div>\n' +
                    '                    <div class="btn btn-default des">-</div>\n' +
                    '                    </div>';
                $('#options').append(str);
                $('.des').click(function () {
                    $(this).parent().remove()
                })

            })
            $('.des').click(function () {
                $(this).parent().remove()
            })
        });
    </script>
    <script src="{{cdn('js/plugins/webuploader/webuploader.nolog.min.js')}}"></script>
    <script src="{{cdn('js/plugins/webuploader/webuploader_public.js')}}"></script>
    <script type="text/javascript">
        jQuery(function ($) {
            singleUpload({
                _token: '{{csrf_token()}}',
                type_key: 'FT_ARTICLE_IMG',
                item_id: '{{$user->id or 0}}',
                pick: 'filePicker',
                boxid: 'imgupload',
                file_path: 'default_img',
                file_id: 'file_id',
                multi: true,
                maximg: 3
            });
            $('#imgupload').find('.img-div>span').click(function () {
                sUploadDel($(this), 'default_img');
            });
        });
    </script>
@endsection
